import { session } from 'js/util'

export default {
  state: {
    userInfo: session.get('userInfo') || {}
  },
  getters: {
    userInfo: state => state.userInfo,
    token: state => state.userInfo.accessToken,
    mobile: state => state.userInfo.userName,
    nickName: state => state.userInfo.nickName,
    userHeadImg: state => state.userInfo.userHeadImg
  },
  mutations: {
    // 更新用户信息
    updateUserInfo(state, payload) {
      session.set('userInfo', payload)
      state.userInfo = payload
    },
    // 清除用户信息
    clearUserInfo(state) {
      session.remove('userInfo')
      state.userInfo = {}
    }
  }
}
